package com.yong.ssj.exception;


import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class MyException implements HandlerExceptionResolver{

	private static Logger logger = Logger.getLogger(MyException.class);
	
	@Override
	public ModelAndView resolveException(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception ex) {
		//获取堆信息
    	StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try {
            ex.printStackTrace(pw);
            arg0.setAttribute("stackTrace", sw.toString());
        } finally {
        	logger.error(sw.toString());
            pw.close();
        }
        arg0.setAttribute("message" , ex.toString());
    	return new ModelAndView("/common/error");

	}

}
